<!-- Dinamic Sources -->
<script>
function addSource() {
 		document.getElementById('sizesource').value = parseInt(document.getElementById('sizesource').value) + 1;
 	    	var $value = parseInt(document.getElementById('sizesource').value);	    	
 	    	$content = '<table>'
 	    				+'<tr><td><label for="Source_'+ $value +'_title">Referência</label></td><td><label for="Source_'+ $value +'_url">Link</label></td></tr>'
 	    				+'<tr><td><input class="span3" maxlength="45" name="Source['+$value+'][title]" id="Source_'+$value+'_title" type="text"></td>'
 	    				
 	    				+'<td><input class="span3" maxlength="250" name="Source['+$value+'][url]" id="Source_'+$value+'_url" type="text"></td></tr></table>';
 	    				
 	    	document.getElementById('sources').innerHTML = document.getElementById('sources').innerHTML + $content;
}

</script> 
 
<input id="sizesource" name="sizesource" type="hidden" value="<?php echo count($sources)?>" >


<div id="sources" >
	<?php $cont = 0; 
	if(Utils::hasContent($sources)) {
	foreach($sources as $source) {
		//echo $this->renderPartial('_form', array('form'=>$form,'model'=>$source, 'position'=>$cont++));
		
		echo '<table>'
			.'<tr><td><label for="Source_'. $cont .'_title">Referência</label></td><td><label for="Source_'. $cont .'_url">Link</label></td></tr>'
				.'<tr><td><input class="span3" maxlength="45" name="Source['.$cont.'][title]" id="Source_'.$cont.'_title" type="text" value="'.$source->title.'"></td>'
						.'<td><input class="span3" maxlength="250" name="Source['.$cont.'][url]" id="Source_'.$cont.'_url" type="text" value="'.$source->url.'"></td></tr></table>';
		$cont ++;
	}
	}else {
		echo '<table>'
		.'<tr><td><label for="Source_0_title">Referência</label></td><td><label for="Source_0_url">Link</label></td></tr>'
				.'<tr><td><input class="span3" maxlength="45" name="Source[0][title]" id="Source_0_title" type="text"></td>'
						.'<td><input class="span3" maxlength="250" name="Source[0][url]" id="Source_0_url" type="text"></td></tr></table>';
	}
	?>
</div>

<input type="button" id="addsource" name="addsource" value="Adicionar Referência" onClick="addSource();">
<?php if(!$hasSource) { ?>
	<p style="color: #b94a48;">Nenhuma fonte inserida.</p>
<?php }?>
<br/>
<br/>